package sunlight.database;

import java.util.HashMap;

/**
 * colectie de variabile statice pentru a reprezenta numele tabelelor specifice
 * aplicatiei in baza de date;
 * 
 * @author 	Adrian &#350;ilimon
 * @version	1.1
 */
public class DatabaseTables {
	
	private static HashMap<String, String> Tables = new HashMap<String, String>();
	private static String 	Prefix 				   = new String();
	
	private static String[] TablesArray;
	private static String[] LIDSArray;
	
	public static void setPrefix(String prefix){
		Prefix = prefix;
	}
	
	public static void add(String table, String localIdentifier){
		Tables.put(localIdentifier, Prefix + table);
	}
	
	
	public static void setLocalIdentifiers(String... identifiers){
		
		LIDSArray = new String[identifiers.length];
		
		for(int i=0; i<identifiers.length; i++){
			LIDSArray[i] = identifiers[i];
		}
		
		set(LIDSArray, TablesArray);
	}
	
	public static void setTables(String... tables){
		
		TablesArray = new String[tables.length];
		
		for(int i=0; i<tables.length; i++){
			TablesArray[i] = tables[i];
		}
		
		set(LIDSArray, TablesArray);
	}
	
	private static void set(String[] ids, String[] tables){
		
		if((LIDSArray != null) && (TablesArray != null)){
			if((LIDSArray.length > 0) && (TablesArray.length > 0)){
				for(int i=0; i<ids.length; i++){
					add(tables[i], ids[i]);
				}
			}
		}
	}
	
	public static String get(String localIdentifier){
		return Tables.get(localIdentifier);
	}
	
	public static String _(String id){
		return Tables.get(id);
	}
}
